SqueezeNet

SqueezeNet

背景介绍

  SqueezeNet:是一种轻量级深度神经网络模型,在2017年发表于ICLR,作者来自Berkeley和Stanford,其只用1/50的参数量,可以达到与AlexNet相同的精度,其核心结构为Fire Module

SqueezeNet

SqueezeNet特点

  引入Fire Module,根据降维思想,先通过1x1的卷积核对参数量进行压缩,然后采用了Inception的思想,进行多路融合。

SqueezeNet图像分析

SqueezeNet

TensorFlow2.0实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from functools import reduce
import tensorflow.keras as keras


def compose(*funcs):
if funcs:
return reduce(lambda f, g: lambda *a, **kw: g(f(*a, **kw)), funcs)
else:
raise ValueError('Composition of empty sequence not supported.')


def fire_block(x, s1, e1, e3, name):
x = keras.layers.Conv2D(s1, (1, 1), activation='relu', name='{}_conv'.format(name))(x)
x1 = keras.layers.Conv2D(e1, (1, 1), activation='relu', name='{}_part1_conv'.format(name))(x)
x2 = keras.layers.Conv2D(e3, (3, 3), padding='same', activation='relu', name='{}_part2_conv'.format(name))(x)
x = keras.layers.Concatenate(name='{}_concatenate'.format(name))([x1, x2])

return x


def squeezenet(input_shape):
input_tensor = keras.layers.Input(input_shape, name='input')
x = input_tensor

x = compose(keras.layers.Conv2D(96, (7, 7), (2, 2), padding='same', activation='relu', name='conv1'),
keras.layers.MaxPool2D((3, 3), (2, 2), name='maxpool'))(x)

x = fire_block(x, 16, 64, 64, 'fire_block1_1')
x = fire_block(x, 16, 64, 64, 'fire_block1_2')

x = fire_block(x, 32, 128, 128, 'fire_block2_1')
x = keras.layers.MaxPool2D((3, 3), (2, 2), name='fire_block2_maxpool')(x)
x = fire_block(x, 32, 128, 128, 'fire_block2_2')

x = fire_block(x, 48, 192, 192, 'fire_block3_1')
x = fire_block(x, 48, 192, 192, 'fire_block3_2')

x = fire_block(x, 64, 256, 256, 'fire_block4_1')
x = keras.layers.MaxPool2D((3, 3), (2, 2), name='fire_block4_maxpool')(x)
x = fire_block(x, 64, 256, 256, 'fire_block4_2')

x = compose(keras.layers.Dropout(0.5, name='dropout'),
keras.layers.Conv2D(1000, (1, 1), activation='relu', name='conv2'),
keras.layers.GlobalAveragePooling2D(name='global_averagepool'),
keras.layers.Softmax(name='softmax'))(x)

model = keras.Model(input_tensor, x, name='SqueezeNet')

return model


if __name__ == '__main__':

model = squeezenet(input_shape=(224, 224, 3))
model.build(input_shape=(None, 224, 224, 3))
model.summary()

SqueezeNet

SqueezeNet小结

  SqueezeNet是一种简单的轻量级深度学习网络,从上图可以看出SqueezeNet模型的参数量只有1M,因此在某些特殊场合中能够发挥出很好的效果。

-------------本文结束感谢您的阅读-------------
0%